package job;

import java.util.List;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.zty.spring.cloud.entity.City;
import com.zty.spring.cloud.service.CityDataService;
import com.zty.spring.cloud.service.WeatherDataService;

public class WeatherDataSyncJob extends QuartzJobBean {
	
	private static final Logger logger = LoggerFactory.getLogger(WeatherDataSyncJob.class);
	@Autowired
	private CityDataService  cityDataService;
	@Autowired
	private WeatherDataService weatherDataService;

	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		logger.info("Weather Data Sync Job. Start！");
		List<City> findByListCity=null;
		try {
			findByListCity = cityDataService.findByListCity();
		} catch (Exception e) {
			logger.error("Exception",e);
		}
		for (City city : findByListCity) {
			String cityId = city.getCityId();
			logger.info("Weather Data Sync Job, cityId:" + cityId);
			weatherDataService.getDataByCityId(cityId);
		}
		logger.info("Weather Data Sync Job. End！");
	}

}
